/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InserirComponentes.java
 *
 * Created on 04/06/2011, 10:49:20
 */

package campeonatobrasuka;

import Persistencia.daos.EstadioDAO;
import Persistencia.daos.TecnicoDAO;
import Persistencia.daos.TimeDAO;
import javax.swing.JOptionPane;

/**
 *
 * @author Jaqueline Ishiyama
 */
public class InserirComponentes extends javax.swing.JPanel {
// colocar o while
    /** Creates new form InserirComponentes */
    public InserirComponentes() {
       initComponents();

       this.jRadioButton6.setEnabled(true);// radio do tecnico
        this.jRadioButton5.setEnabled(true);//radio do arbitro
        this.jRadioButton4.setEnabled(true);// radio do estadio
        this.jRadioButton7.setEnabled(true);//radio do presidente
        this.jRadioButton1.setEnabled(true);//  radio do Clube
        this.jRadioButton2.setEnabled(true);// radio do jogador
        this.jRadioButton8.setEnabled(true);//radio de partida
            
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jRadioButton8 = new javax.swing.JRadioButton();
        jRadioButton9 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(campeonatobrasuka.CampeonatoBrasukaApp.class).getContext().getResourceMap(InserirComponentes.class);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 782, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText(resourceMap.getString("jRadioButton1.text")); // NOI18N
        jRadioButton1.setEnabled(false);
        jRadioButton1.setName("jRadioButton1"); // NOI18N

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText(resourceMap.getString("jRadioButton2.text")); // NOI18N
        jRadioButton2.setEnabled(false);
        jRadioButton2.setName("jRadioButton2"); // NOI18N
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setText(resourceMap.getString("jRadioButton4.text")); // NOI18N
        jRadioButton4.setEnabled(false);
        jRadioButton4.setName("jRadioButton4"); // NOI18N

        buttonGroup1.add(jRadioButton5);
        jRadioButton5.setText(resourceMap.getString("jRadioButton5.text")); // NOI18N
        jRadioButton5.setEnabled(false);
        jRadioButton5.setName("jRadioButton5"); // NOI18N

        buttonGroup1.add(jRadioButton6);
        jRadioButton6.setText(resourceMap.getString("jRadioButton6.text")); // NOI18N
        jRadioButton6.setEnabled(false);
        jRadioButton6.setName("jRadioButton6"); // NOI18N

        buttonGroup1.add(jRadioButton7);
        jRadioButton7.setText(resourceMap.getString("jRadioButton7.text")); // NOI18N
        jRadioButton7.setEnabled(false);
        jRadioButton7.setName("jRadioButton7"); // NOI18N

        buttonGroup1.add(jRadioButton8);
        jRadioButton8.setText(resourceMap.getString("jRadioButton8.text")); // NOI18N
        jRadioButton8.setEnabled(false);
        jRadioButton8.setName("jRadioButton8"); // NOI18N

        buttonGroup1.add(jRadioButton9);
        jRadioButton9.setText(resourceMap.getString("jRadioButton9.text")); // NOI18N
        jRadioButton9.setEnabled(false);
        jRadioButton9.setName("jRadioButton9"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("jButton2.toolTipText")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton9)
                            .addComponent(jRadioButton8)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton6)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton7)
                            .addComponent(jRadioButton4)
                            .addComponent(jLabel1))
                        .addContainerGap(71, Short.MAX_VALUE))
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton7)
                .addGap(6, 6, 6)
                .addComponent(jRadioButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton9)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(181, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(55, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jRadioButton2ActionPerformed

    public void atualizaRadioButtons(){

       /*

            if (tecnicoDao.recuperaTodos().size() != 0)
            {
              this.jRadioButton6.setEnabled(true);// radio do tecnico
              this.jRadioButton5.setEnabled(true);//radio do arbitro
              this.jRadioButton1.setEnabled(true);//habilita o radion do Clube

            if (timeDao.recuperaTodos().size() != 0 )
            {
              this.jRadioButton4.setEnabled(true);// radio do estadio
              this.jRadioButton7.setEnabled(true);//radio do presidente
              this.jRadioButton2.setEnabled(true);// radio do jogador
            if (estadioDao.recuperaTodos().size() != 0)
                {
              this.jRadioButton8.setEnabled(true);//radio de partida
                }
            else // caso a tabela estádio não tiver registro
               {
              this.jRadioButton8.setEnabled(false);//radio de partida
                }
            }
            else// caso não tenha registro de clube
            {
              this.jRadioButton4.setEnabled(false);// radio do estadio
              this.jRadioButton7.setEnabled(false);//radio do presidente
              this.jRadioButton2.setEnabled(false);// radio do jogador
            }

        }
        else // caso não tenha técnico
        {

        this.jRadioButton6.setEnabled(true);// radio do tecnico
        this.jRadioButton5.setEnabled(true);//radio do arbitro
        this.jRadioButton4.setEnabled(false);// radio do estadio
        this.jRadioButton7.setEnabled(false);//radio do presidente
        this.jRadioButton1.setEnabled(false);//  radio do Clube
        this.jRadioButton2.setEnabled(false);// radio do jogador
        this.jRadioButton8.setEnabled(false);//radio de partida
        }*/

    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        //código que chama as telas correspondentes ao radiobutton selecionado
        Clube c;
        Jogador j;
        Tecnico tecn;
        Arbitro a;
        Presidente pres;
        Estadio e;
        Partida p;
        Campeonato camp;
       TecnicoDAO tecnicoDao = new TecnicoDAO();
       TimeDAO timeDao = new TimeDAO();
       EstadioDAO estadioDao = new EstadioDAO();



        if (jRadioButton1.isSelected()){
            if (tecnicoDao.recuperaTodos().size() != 0) {
            c = new Clube();
            jScrollPane1.setViewportView(c);}
            else{
                JOptionPane.showMessageDialog(null, "É preciso inserir um técnico!" ,"Alerta",JOptionPane.WARNING_MESSAGE);
            }
        }
    else if(jRadioButton2.isSelected()){
        if(timeDao.recuperaTodos().size() != 0){
            j = new Jogador();
            jScrollPane1.setViewportView(j);
        }
        else{
        JOptionPane.showMessageDialog(null, "É preciso inserir um time!" ,"Alerta",JOptionPane.WARNING_MESSAGE);
        }
    }
 else if (jRadioButton6.isSelected()) {
            tecn = new Tecnico();
            jScrollPane1.setViewportView(tecn);
        }

 else if (jRadioButton5.isSelected()) {
            a = new Arbitro();
            jScrollPane1.setViewportView(a);
        } 
       
    else if (jRadioButton7.isSelected() ){
        if (timeDao.recuperaTodos().size() != 0) {
            pres = new Presidente();
            jScrollPane1.setViewportView(pres);
        } 
        else{
        JOptionPane.showMessageDialog(null, "É preciso inserir um time!" ,"Alerta",JOptionPane.WARNING_MESSAGE);
        }
        }
   else if (jRadioButton4.isSelected()){
      if(timeDao.recuperaTodos().size() != 0) {
            e = new Estadio();
            jScrollPane1.setViewportView(e);
        } 
       else{
        JOptionPane.showMessageDialog(null, "É preciso inserir um time!" ,"Alerta",JOptionPane.WARNING_MESSAGE);
        }
    }
 else if (jRadioButton8.isSelected()){
     if((timeDao.recuperaTodos().size() != 0) && (estadioDao.recuperaTodos().size() != 0)){
            p = new Partida();
            jScrollPane1.setViewportView(p);
        } 
        else{
        JOptionPane.showMessageDialog(null, "É preciso inserir um time e um estádio!" ,"Alerta",JOptionPane.WARNING_MESSAGE);
        }}
else if (jRadioButton9.isSelected()) {
            camp = new Campeonato();
            jScrollPane1.setViewportView(camp);

        }
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // EVENTO DO BOTÃO CONSULTAR COMPONENTES JA CADASTRADOS
        TelaConsultas nova = new TelaConsultas();
        jScrollPane1.setViewportView(nova);

    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JRadioButton jRadioButton8;
    private javax.swing.JRadioButton jRadioButton9;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
